#include "source/util.hpp"
#include "source/data.hpp"
#include "source/server.hpp"

void FileTest()
{
   aod::FileUtil("./www").CreateDirectory();
   aod::FileUtil("./www/login.html").SetContent("<html></html>");
   std::string body;
   aod::FileUtil("./www/login.html").GetContent(&body);
   std::cout << body << std::endl;
   std::cout << aod::FileUtil("./www/login.html").Size() << std::endl;
   aod::FileUtil("./www").Exists();
}

void JsonTest()
{
   Json::Value val;
   val["姓名"] = "小张";
   val["年龄"] = 18;
   val["性别"] = "男";
   val["成绩"].append(77.5);
   val["成绩"].append(71.5);
   val["成绩"].append(72.5);

   std::string body;
   aod::JsonUtil::Serialize(val, &body);
   std::cout << body << std::endl;

   Json::Value stu;
   aod::JsonUtil::UnSerialize(body, &stu);
   std::cout << stu["姓名"].asString() << std::endl;
   std::cout << stu["年龄"].asInt() << std::endl;
   std::cout << stu["性别"].asString() << std::endl;
   for (auto &a : stu["成绩"])
   {
      std::cout << a.asFloat() << " ";
   }
   std::cout << std::endl;
}

void DataTest()
{
   aod::TableVideo tb_video;
   Json::Value video;

   // video["name"] = "变形金刚";
   // video["info"] = "变形金刚的故事";
   // video["video"] = "/video/iron.mp4";
   // video["image"] = "/image/iron.jpg";
   // tb_video.Insert(video);
   // tb_video.SelectOne(2,&video);
   // tb_video.SelectLike("金", &video);
   // std::string body;
   // aod::JsonUtil::Serialize(video, &body);
   // std::cout << body << std::endl;
   tb_video.Delete(1);
}

void userInsert()
{
   aod::TableUser tb_user;
   tb_user.Register("HYN", "123321", true);
}

void ServerTest()
{
   int _port = 8888;
   aod::Server server(_port);
   printf("端口[%d]启动成功!\n", _port);
   server.RunModule();
}

int main()
{
   // DataTest();
   ServerTest();
   return 0;
}
